package com.hackerrank.challenges.findhackerrank;

import java.util.Scanner;

public class Solution {
	private static String H = "hackerrank";
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		for(int n = 0; n < N; n++) {
			String l = in.nextLine();
			if(l.startsWith(H)) {
				if(l.endsWith(H))
					System.out.println(0);
				else
					System.out.println(1);
			} else if(l.endsWith(H))
				System.out.println(2);
			else
				System.out.println(-1);
		}
	}
}
